home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Small Eiffel 0.4.8 / lib_std / fixed_array2.e < prev    next >
Text File  |  1997-04-13  |  2KB  |  83 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class FIXED_ARRAY2[E]
  5.    -- 
  6.    -- Implementation of COLLECTION[E] with frozen lower bounds :
  7.    -- `lower1' and `lower2' are frozen to 0. Some memory is saved 
  8.    -- and looping toward lower bounds runs a little bit faster.
  9.    --
  10.    
  11. inherit COLLECTION2[E] redefine copy end;
  12.    
  13. creation make, array2
  14.  
  15. feature {FIXED_ARRAY2}
  16.    
  17.    storage: FIXED_ARRAY[like item];
  18.  
  19. feature
  20.  
  21.    lower1, lower2: INTEGER is 0;
  22.  
  23.    upper1, upper2, count1, count2: INTEGER;
  24.  
  25. feature 
  26.    
  27.    make(size1, size2: INTEGER) is
  28.      -- Reset `count1' and `count2' using arguments as new
  29.      -- values. All elements are set to the default value of 
  30.      -- type E.
  31.       require
  32.      size1 > 0;
  33.      size2 > 0
  34.       do
  35.      count1 := size1;
  36.      count2 := size2;
  37.      if storage /= Void then
  38.         storage.free;
  39.      end;
  40.      upper1 := size1 - 1;
  41.      upper2 := size2 - 1;
  42.      !!storage.make(count);
  43.       ensure
  44.      count1 = size1;
  45.      count2 = size2;
  46.      upper1 = size1 - 1;
  47.      upper2 = size2 - 1
  48.       end;
  49.    
  50. feature 
  51.    
  52.    item(i1, i2: INTEGER): E is
  53.       do
  54.      Result := storage.item(i1 * count1 + i2);
  55.       end;
  56.    
  57.    put(x: like item; i1, i2: INTEGER) is
  58.       do
  59.      storage.put(x,i1 * count1 + i2);     
  60.       end;
  61.    
  62.    copy(other: like Current) is
  63.       local
  64.      i: INTEGER;
  65.       do
  66.      make(other.count1,other.count2);
  67.      storage.copy(other.storage);
  68.       end;
  69.    
  70. invariant
  71.  
  72.    upper1 > 0;
  73.  
  74.    upper2 > 0;
  75.  
  76.    count1 = upper1 + 1;
  77.  
  78.    count2 = upper2 + 1;
  79.  
  80.    storage.count = count;
  81.    
  82. end -- FIXED_ARRAY2
  83.